package com.example.sampleworks.ui;

import java.util.List;

import com.example.sampleworks.R;



import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class CustomListViewAdapter extends ArrayAdapter<RowItem> {

	Context context;
	
	 public CustomListViewAdapter(Context context, int resourceId, List<RowItem>  items) {
		 super(context, resourceId, items);
		   this.context = context;
	 }
	 private class ViewHolder {
		 ImageView imageView;
		 TextView textTitle;
		 TextView textDesc;
		  }
	 
	 public View getView(int position, View convertView, ViewGroup parent) {
		 ViewHolder holder = null;
		 RowItem rowItem = getItem(position);
		 
		 LayoutInflater mInflater = (LayoutInflater) context
				 .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
		 if (convertView == null) {
			 convertView = mInflater.inflate(R.layout.list_item1, null);
			 holder = new ViewHolder();
			 holder.textTitle = (TextView) convertView.findViewById(R.id.textView1);
			 holder.textDesc = (TextView) convertView.findViewById(R.id.textView2);
			 holder.imageView = (ImageView) convertView.findViewById(R.id.imageView1);
			 convertView.setTag(holder);
		 } else
			 holder = (ViewHolder) convertView.getTag();
		 
		 holder.textTitle.setText(rowItem.getTitle());
		 holder.textDesc.setText(rowItem.getDesc());
		 holder.imageView.setImageResource(rowItem.getImageId());
		 
		 return convertView;
		 
		 
	 }
		
	
}
